<!DOCTYPE html>
<html lang="en" class="dark">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
    <link
      rel="stylesheet"
      href="//unpkg.com/element-plus/theme-chalk/dark/css-vars.css"
    />
    <script src="./vue.js"></script>
    <script src="//unpkg.com/element-plus"></script>
    <script src="//unpkg.com/element-plus/dist/locale/zh-cn"></script>
    <script src="./axios.min.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .mylist {
        width: 1200px;
        margin: 10px auto;
        display: flex;
        flex-wrap: wrap;
      }
      .mylist li {
        list-style: none;
        width: 280px;
        margin: 10px;
      }

      .mylist img {
        width: 100%;
      }
      .mylist h3 {
        line-height: 50px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 列表渲染 -->
      <tag-list id="2189" :page="page"></tag-list>
      <!-- 分页 -->
      <el-pagination
        layout="prev, pager, next"
        :total="200"
        background
        :page-size="20"
        v-model:current-page="page"
      ></el-pagination>
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          page: 1,
        };
      },
    });

    // 组件
    app.component("tag-list", {
      props: ["id", "page"],
      template: `
         <ul class="mylist">
            <li v-for="item in list">
              <img :src="item.img" alt="" />
              <h3>{{item.name}}</h3>
            </li>
          </ul>
      `,
      data() {
        return {
          list: [],
        };
      },
      created() {
        this.getList();
      },
      methods: {
        async getList() {
          let { data } = await axios.get(
            "http://localhost:6060/api/www/classify/playlist/getTagPlayList?pn=" +
              this.page +
              "&rn=20&id=" +
              this.id
          );
          this.list = data.data.data;
        },
      },
      watch: {
        page() {
          this.getList();
        },
      },
    });

    // mounted  beforeUnmount
    app = app
      .use(ElementPlus, {
        locale: ElementPlusLocaleZhCn,
      })
      .mount("#app");
  </script>
</html>
